package com.kfm.jdbc.day0403;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.List;

public class Demo03 {

    public static void main(String[] args) {
        String json = "[{\"id\":1,\"name\":\"张三\",\"en\":\"zhangsan\",\"age\":24},{\"id\":2,\"name\":\"李四\",\"en\":\"lisi\",\"age\":23}]";

        ObjectMapper mapper = new ObjectMapper();

        try {
            List<Student> students = mapper.readValue(json, new TypeReference<List<Student>>() {
            });
//            for (Student student : students){
//                System.out.println(student);
//            }

            String s = mapper.writeValueAsString(students);
            System.out.println(s);

        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
